﻿package com.bizmlib.ui.composite
{
	
	
	public class UIQueueManager extends UICompositeManager
	{
		
		public function UIQueueManager()
		{
		}
		
		
		override protected function startShowImplementation():void
		{
			//trace(this + ".startShowImplementation(" + arguments + ")");
			
			if(queuedItems.length>0 && showItems.length==0)
			{
				showItems.push(queuedItems.shift());
				(showItems[showItems.length-1] as IUICompositeItem).show();
			}
		}
		override protected function completeShow():Boolean
		{
			//trace(this + ".completeShow(" + arguments + ")");
			
			if(super.completeShow())
			{
				return true;
			}
			else if(queuedItems.length>0)
			{
				showItems.push(queuedItems.shift());
				(showItems[showItems.length-1] as IUICompositeItem).show();
				return false;
			}
			else
			{
				return false;
			}
		}
		
		override protected function startHideImplementation():void
		{
			if(visibleItems && visibleItems.length>0)
			{
				var item:IUICompositeItem = visibleItems.shift() as IUICompositeItem;
				if(item)
				{
					hideItems.push(item);
					item.hide();
				}
				else
				{
					completeHide();
				}
			}
		}
		override protected function completeHide():Boolean
		{
			if(super.completeHide())
			{
				return true;
			}
			else if(visibleItems.length>0)
			{
				var item:IUICompositeItem = visibleItems.shift() as IUICompositeItem;
				if(item)
				{
					hideItems.push(item);
					item.hide();
				}
				else
				{
					completeHide();
				}
				return false;
			}
			else
			{
				return false;
			}
		}
		
		override public function toString():String
		{
			return "[UIQueueManager	state:" + state + "	visible:" + visibleItems.length + "	queued:" + queuedItems.length + "	items to show:" + showItems.length + "		items to hide:" + 
					hideItems.length + "		items to remove:" + removeItems.length + "]";
		}
	}
}